package net.lzzy.chapter427;

import java.util. *;
public class PriorityQueueDemo {
    public static void main(String[] args) {
        //创建Queue接口对象，实现插入提取等优先队列操作
        PriorityQueue<String> queuel = new PriorityQueue<>();
        // offer()插入一个元素到队列中
        queuel.offer("0klahoma");
        queuel.offer("Indiana");
        queuel.offer("Georgia");
        queuel.offer("Texas");

        System.out.println("Priority queue using Comparable:");
        while (queuel.size() > 0) {
            //remove（）获取并且移除队列的头元素，如果队列为空则抛出异常
            System.out.print(queuel.remove() + " ");
        }
        PriorityQueue<String> queue2 = new PriorityQueue(
                4, Collections.reverseOrder());
        queue2.offer("Oklahoma");
        queue2.offer("Indiana");
        queue2.offer("Georgia");
        queue2.offer("Texas");

        System.out.println("\nPriority queue using Comparator:");
        while (queue2.size() > 0) {
            System.out.print(queue2.remove() + " ");
        }
    }
}